<?php

/**
 * Created by PhpStorm.
 * User: 张彪
 * Date: 2016/5/9 0009
 * Time: 下午 2:46
 */
class Comment_model extends Base_Model
{
    public function __construct()
    {
        $this->load->database();
    }

    /**
     * @param $data
     * @return array
     * 获取 评论
     */
    public function getActivityOrTrackComments($data)
    {

        if(!empty($data['type']))
        {
            $this->db->where('type', $data['type']);
        }
        if(!empty($data['id']))
        {
            $key = empty($data['key'])?'track_id':$data['key'];
            $this->db->where("{$key}", $data['id']);
        }

        if (!empty($data['$offset']) && !empty($data['limit'])) {
            $this->db->limit($data['$offset'], $data['limit']);
        }

        $this->db->from('mod_track_comments as co');
        $this->db->join('user_v2 as u', 'u.uid = co.uid', 'left');
        $query = $this->db->get()->result_array();
        $items = array();
        foreach ($query as $q)
        {
            $item = array();
            $item['userName'] = $q['userName'];
            $item['userIcon'] = $q['userIcon'] ;
            $item['created'] = empty($q['created'])?'':date('Y.m.d H:i:s',$q['created']);
            $imgs = explode(';',$q['tourist_pic']);
            $is = array();
            foreach($imgs as $i)
            {
                if(!empty($i))
                {
                    $is[] = $this->img($i);
                }

            }
            $q['tourist_pic'] = json_encode($is);
            $items[] = $q;
        }

        return $items;


    }

}